<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>代理商提现管理</title>
    <link rel="stylesheet" type="text/css" href="/themes/default/easyui.css" id="swicth-style">
    <link rel="stylesheet" type="text/css" href="/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/css/common.css">
    <link rel="stylesheet" type="text/css" href="/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="/themes/color.css">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="/js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
</head>

<body class="easyui-layout" style="padding:5px">
<fieldset>
    <legend>信息查询</legend>
    <form id="ffSearch" method="post">
        <div id="searchBar">
            <table cellspacing="0" cellpadding="0">
                <tr>
                    <th>统一社会信用代码：</th>
                    <td style="width:120px">
                        <input type="hidden" name="companyType" value="1">
                        <input name="socialCode" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <th>公司名称：</th>
                    <td style="width:120px">
                        <input name="name" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <th>公司地址：</th>
                    <td style="width:120px">
                        <input name="address" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <td colspan="2">
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                           onclick="onSearch()">查询</a>&nbsp;&nbsp;
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'"
                           onclick="onClear()">重置</a>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</fieldset>

<table id="dg"></table>
<!--提现记录-->
<div id="withdraw" class="easyui-window" title="提现记录"
     data-options="closed:true,iconCls:'icon-save',footer:'#withdraw_ft1'" style="width:90%;paddin:100px;">
    <div id="withdraw_dl"></div>
    <div id="withdraw_ft1" style="padding:5px;text-align: right;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)"
           onclick="closeWindow()" style="width:80px">关闭</a>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        var dg = $('#dg').datagrid();
        var queryParams = $('#ffSearch').serializeObject();
        $('#ffSearch').form('clear');
        dg.datagrid({
            url:'/v1/api0/agent_Account/list',
            queryParams: queryParams,
            columns:[[
                {field:'accountID',checkbox:true},
                {field:'companyID',hidden:true},
                {field:'companyName',title:'代理商名称',width:100},
                {field:'socialCode',title:'代理商统一信贷码',width:100},
                {field:'status',title:'状态',width:60,formatter: function(value,row,index){
                    switch(value) {
                        case 1: return "启用";
                        case 2: return "禁用";
                    }
                }},
                {field:'profit',title:'可提现金额',width:100,align:'center'},
                {field:'action',title:'操作',width:120,formatter: function(value,row,index){
                        return '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="listWithdraw(\''+row.accountID+'\')">查看提现记录</a>';
                }}
            ]],
            title:'代理商提现管理',
            pagination: true,
            iconCls: 'icon-application_view_detail',
            singleSelect: true,
            toolbar: [ {
                id: 'btnReload',
                text: '刷新',
                iconCls: 'icon-reload',
                handler: function () {
                    $("#dg").datagrid("reload");
                }
            }]
        });

        var heightMargin = $("#searchBar").height() + 45;
        $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        $(window).resize(function() {
            $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        });
    });

    function onSearch(){
        var queryParams = $('#ffSearch').serializeObject();
        $('#dg').datagrid({
            url:'/v1/api0/agent_Account/list',
            queryParams: queryParams
        });
    }

    function onClear() {
        $('#ffSearch').form('clear');
        $('#statusSelect').combobox('setValue', '0');
        onSearch();
    }
    //列出消费记录
    function listWithdraw(AccountID){
    if(AccountID == null ||AccountID=='null'||AccountID==undefined){
    top.window.showMessage("公司无账户！");
    return;
    }
    showWithdrawWindow(AccountID);
    }
    function showWithdrawWindow(id) {
       var  queryParams = id;
       var dg = $('#withdraw_dl').datagrid();
       dg.datagrid({
            url:'/v1/api0/consume_Record/list',
            queryParams: {accountId:queryParams,account_type:3,type:2},//设置账户类型为收益账户，消费方式：提现(1普通消费，2提现)
            columns:[[
                {field:'id',hidden:true},
                {field:'name',title:'提现名称',width:60},
                {field:'status',title:'状态',width:60},
                {field:'sequenceNumber',title:'序列号',hidden:true},
                {field:'createTime',title:'创建时间',width:60},
                {field:'updateTime',title:'更新时间',width:100},
                {field:'creater',title:'创建人',width:60},
                {field:'createrId',title:'创建人ID',hidden:true},
                {field:'amount',title:'提现金额',width:100},
                {field:'consume_method',title:'提现方式',width:100},
                {field:'type',title:'类型(提现、消费)',hidden:true},
                {field:'remarks',title:'备注',width:100},
                {field:'accountId',title:'账户ID',hidden:true},
                {field:'action',title:'操作',formatter: function(value,row,index){
                    if(row.status == 2){
                         return '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="agree(\''+row.id+'\',\''+row.accountId+'\',,\''+row.amount+'\')">同意申请</a>  | ' +
                            '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="disAgree(\''+row.id+'\')">拒绝申请</a>';
                    }else{
                    return "已完成";
                    }
                }}
            ]],
            pagination: true,
            iconCls: 'icon-application_view_detail',
            singleSelect: true,
        });
        $('#withdraw').window('open');
    }

    function closeWindow(){
        $('#withdraw').window('close');
        //$('#partner').window('close');
    }
    //同意提现
    function agree(recordID,accountID,amount){
        var url = "/v1/api0/withdraw/agree";
        var data = {recordID: recordID};
        $.ajax(ajaxOption(url, data));
    }
    //拒绝提现
    function disAgree(recordID){
        var url = "/v1/api0/withdraw/disAgree";
        var data = {recordID: recordID};
        $.ajax(ajaxOption(url, data));
    }
function ajaxOption(url, data) {
        return {
            type: "post",
            url: url,
            data: data,
            datatype: "json",
            beforeSend: function () {
                $('#withdraw_dl').datagrid('loading');
            },
            success: function (data) {
                if(data.code == 200) {
                    $('#withdraw_dl').datagrid('reload');
                    top.window.showMessage();
                } else {
                    top.window.showMessage(data.msg);
                    $('#withdraw_dl').datagrid('loaded');
                }
            },
            error: function () {
                $('#withdraw_dl').datagrid('loaded');
            }
        }
    }

</script>
</body>
</html>
